local json = require "cjson"
local RestResponse = class()

function RestResponse:ctor()
	self.code = 0
	self.data = null
	self.message = ""
end

RestResponse.ok = function(pData)
	local rtn = RestResponse:new()
	rtn.code = 200
	rtn.data = pData
	return rtn
end

RestResponse.err = function(pMsg)
	local rtn = RestResponse:new()
	rtn.code = 500
	rtn.message = pMsg
	return rtn
end

function RestResponse:toJson()
	local raw_data = {
		code = self.code,
		data = self.data,
		message = self.message
	}
	return json.encode(raw_data)
end

_G.RestResponse = RestResponse